// 可被混入的功能类
class CanEat {
    name: string = "Zkdsads"

    eat() {
        console.log("I can eat");
    }
}

class CanWalk {
    age: number = 12

    walk() {
        console.log("I can walk");
    }
}

// 混入函数的目标类（必须为空实现）
class PersonMinx implements CanEat, CanWalk {
    eat!: () => void;
    walk!: () => void;
    age: number = 1;
    name: string = "dasd";

}

// 实现混入
function applyMixins(targetClass: any, baseClasses: any[]) {
    baseClasses.forEach(baseClass => {

        console.dir(Object.getOwnPropertyNames(baseClass.prototype))
        Object.getOwnPropertyNames(baseClass.prototype).forEach(name => {
            if (name !== 'constructor') {
                Object.defineProperty(
                    targetClass.prototype,
                    name,
                    Object.getOwnPropertyDescriptor(baseClass.prototype, name)!
                );
            }
        });
    });
}

applyMixins(PersonMinx, [CanEat, CanWalk]);

// 使用
const p2 = new PersonMinx();
p2!.eat(); // I can eat
p2!.walk(); // I can walk
console.log(
    p2.age
)